package com.lzycug.server;

import com.lzycug.utils.ConfigUtil;
import org.apache.commons.lang3.StringUtils;

public class Consumer extends Thread {
    private static volatile int cash_count = 1;

    private static volatile int card_count = 1;

    private static final int cash_max = Integer.parseInt(ConfigUtil.getProperty("bank.server.limit.cash"));

    private int card_max = Integer.parseInt(ConfigUtil.getProperty("bank.server.limit.card"));

    private String task;

    private String client;

    public Consumer(String task, String client) {
        this.task = task;
        this.client = client;
    }

    @Override
    public void run() {
        synchronized (this) {
            while (card_count <= card_max || cash_count <= cash_max) {
                if (StringUtils.equalsAnyIgnoreCase("cash", task) && cash_count <= cash_max) {
                    System.out.println(Thread.currentThread().getName() + "---" + client + "号机：现金业务，请" + cash_count++ + "号前来办理业务");
                } else if (card_count <= card_max) {
                    System.out.println(Thread.currentThread().getName() + "---" + client + "号机：开户业务，请" + card_count++ + "号前来办理业务");
                }
            }
        }
    }
}